<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Cache;

class HotKeyword extends Model
{
    protected $guarded = [];
    public $timestamps = false;

    public function getKeywords()
    {
        return $this->keywordsList();
        /*return Cache::remember('book-shop:hot-keywords:list', 24*60, function(){
            return $this->keywordsList();
        });*/
    }

    private function keywordsList()
    {
        $list = $this->newQuery()->where('deleted',0)->orderBy('id','desc')->get();

        $items = [];
        if(!empty($list))
        {
            foreach ($list as $v)
            {
                $items[] = [
                    'keyword' => $v->keyword,
                ];
            }
        }

        return $items;
    }
}
